﻿using System;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.nodes.mssql;
using SharpSqlAnalyzer.nodes.oracle;

namespace SharpSqlAnalyzer.stmt
{
	// Token: 0x0200009E RID: 158
	public class TDeleteSqlStatement : TCustomSqlStatement
	{
		// Token: 0x170000BF RID: 191
		// (get) Token: 0x060004E2 RID: 1250 RVA: 0x002FC07A File Offset: 0x002FA27A
		// (set) Token: 0x060004E1 RID: 1249 RVA: 0x002FC071 File Offset: 0x002FA271
		public virtual bool FromKeyword
		{
			get
			{
				return this._fromKeyword;
			}
			set
			{
				this._fromKeyword = value;
			}
		}

		// Token: 0x170000C0 RID: 192
		// (get) Token: 0x060004E3 RID: 1251 RVA: 0x002FC082 File Offset: 0x002FA282
		// (set) Token: 0x060004E4 RID: 1252 RVA: 0x002FC08A File Offset: 0x002FA28A
		public virtual TErrorLoggingClause ErrorLoggingClause
		{
			get
			{
				return this._errorLoggingClause;
			}
			set
			{
				this._errorLoggingClause = value;
			}
		}

		// Token: 0x170000C1 RID: 193
		// (get) Token: 0x060004E5 RID: 1253 RVA: 0x002FC093 File Offset: 0x002FA293
		// (set) Token: 0x060004E6 RID: 1254 RVA: 0x002FC09B File Offset: 0x002FA29B
		public virtual TOptionClause OptionClause
		{
			get
			{
				return this._optionClause;
			}
			set
			{
				this._optionClause = value;
			}
		}

		// Token: 0x170000C2 RID: 194
		// (get) Token: 0x060004E8 RID: 1256 RVA: 0x002FC0AD File Offset: 0x002FA2AD
		// (set) Token: 0x060004E7 RID: 1255 RVA: 0x002FC0A4 File Offset: 0x002FA2A4
		public virtual TSourceToken DeleteToken
		{
			get
			{
				return this._deleteToken;
			}
			set
			{
				this._deleteToken = value;
			}
		}

		// Token: 0x170000C3 RID: 195
		// (get) Token: 0x060004E9 RID: 1257 RVA: 0x002FC0B5 File Offset: 0x002FA2B5
		// (set) Token: 0x060004EA RID: 1258 RVA: 0x002FC0BD File Offset: 0x002FA2BD
		public virtual TOrderBy OrderByClause
		{
			get
			{
				return this._orderByClause;
			}
			set
			{
				this._orderByClause = value;
			}
		}

		// Token: 0x170000C4 RID: 196
		// (get) Token: 0x060004EB RID: 1259 RVA: 0x002FC0C6 File Offset: 0x002FA2C6
		// (set) Token: 0x060004EC RID: 1260 RVA: 0x002FC0CE File Offset: 0x002FA2CE
		public virtual TLimitClause LimitClause
		{
			get
			{
				return this._limitClause;
			}
			set
			{
				this._limitClause = value;
			}
		}

		// Token: 0x170000C5 RID: 197
		// (get) Token: 0x060004ED RID: 1261 RVA: 0x002FC0D7 File Offset: 0x002FA2D7
		// (set) Token: 0x060004EE RID: 1262 RVA: 0x002FC0F2 File Offset: 0x002FA2F2
		public virtual TJoinList ReferenceJoins
		{
			get
			{
				if (this._referenceJoins == null)
				{
					this._referenceJoins = new TJoinList();
				}
				return this._referenceJoins;
			}
			set
			{
				this._referenceJoins = value;
			}
		}

		// Token: 0x060004EF RID: 1263 RVA: 0x002FC0FB File Offset: 0x002FA2FB
		public TDeleteSqlStatement(EDbVendor dbvendor) : base(dbvendor)
		{
			this.sqlstatementtype = ESqlStatementType.sstdelete;
		}

		// Token: 0x060004F0 RID: 1264 RVA: 0x002FC10B File Offset: 0x002FA30B
		internal override void buildsql()
		{
		}

		// Token: 0x060004F1 RID: 1265 RVA: 0x002FC10D File Offset: 0x002FA30D
		internal override void clear()
		{
		}

		// Token: 0x060004F2 RID: 1266 RVA: 0x002FC10F File Offset: 0x002FA30F
		internal override string getasprettytext()
		{
			return "";
		}

		// Token: 0x060004F3 RID: 1267 RVA: 0x002FC116 File Offset: 0x002FA316
		internal virtual void iterate(TVisitorAbs pvisitor)
		{
		}

		// Token: 0x060004F4 RID: 1268 RVA: 0x002FC118 File Offset: 0x002FA318
		public override int doParseStatement(TCustomSqlStatement psql)
		{
			if (this.rootNode == null)
			{
				return -1;
			}
			TDeleteSqlNode tdeleteSqlNode = (TDeleteSqlNode)this.rootNode;
			this._fromKeyword = tdeleteSqlNode.FromKeyword;
			if (this.sourcetokenlist.size() == 0)
			{
				base.startToken = tdeleteSqlNode.startToken;
				base.endToken = tdeleteSqlNode.endToken;
			}
			base.doParseStatement(psql);
			this._deleteToken = tdeleteSqlNode.DeleteToken;
			base.scanOracleHint(this._deleteToken);
			if (tdeleteSqlNode.cteList != null)
			{
				this.CteList = tdeleteSqlNode.cteList;
				this.CteList.doParse(this, ESqlClause.cte);
			}
			if (tdeleteSqlNode.TopClause != null)
			{
				tdeleteSqlNode.TopClause.doParse(this, ESqlClause.top);
				this.TopClause = tdeleteSqlNode.TopClause;
			}
			TTable ttable = this.analyzeFromTable(tdeleteSqlNode.TargetTable, new bool?(true));
			ttable.EffectType = ETableEffectType.tetDelete;
			this.TargetTable = ttable;
			if (tdeleteSqlNode.SourceTableList != null)
			{
				for (int i = 0; i < tdeleteSqlNode.SourceTableList.size(); i++)
				{
					TFromTable fromTable = tdeleteSqlNode.SourceTableList.getFromTable(i);
					TJoin tjoin;
					if (fromTable.FromtableType != ETableSource.join)
					{
						tjoin = new TJoin();
						ttable = this.analyzeFromTable(fromTable, new bool?(true));
						ttable.EffectType = ETableEffectType.tetSelect;
						tjoin.Table = ttable;
					}
					else
					{
						tjoin = this.analyzeJoin(fromTable.JoinExpr, null, new bool?(true));
						tjoin.doParse(this, ESqlClause.join);
					}
					this.joins.addJoin(tjoin);
				}
			}
			if (tdeleteSqlNode.ReferenceTableList != null)
			{
				for (int j = 0; j < tdeleteSqlNode.ReferenceTableList.size(); j++)
				{
					TFromTable fromTable2 = tdeleteSqlNode.ReferenceTableList.getFromTable(j);
					TJoin tjoin2;
					if (fromTable2.FromtableType != ETableSource.join)
					{
						tjoin2 = new TJoin();
						ttable = this.analyzeFromTable(fromTable2, new bool?(true));
						tjoin2.Table = ttable;
					}
					else
					{
						tjoin2 = this.analyzeJoin(fromTable2.JoinExpr, null, new bool?(true));
						tjoin2.doParse(this, ESqlClause.join);
					}
					this.ReferenceJoins.addJoin(tjoin2);
				}
			}
			if (tdeleteSqlNode.OutputClause != null)
			{
				tdeleteSqlNode.OutputClause.doParse(this, ESqlClause.output);
				this.OutputClause = tdeleteSqlNode.OutputClause;
			}
			if (tdeleteSqlNode.WhereCondition != null)
			{
				tdeleteSqlNode.WhereCondition.doParse(this, ESqlClause.where);
				this.WhereClause = tdeleteSqlNode.WhereCondition;
			}
			if (tdeleteSqlNode.ReturningClause != null)
			{
				tdeleteSqlNode.ReturningClause.doParse(this, ESqlClause.returning);
				this.ReturningClause = tdeleteSqlNode.ReturningClause;
			}
			this._orderByClause = tdeleteSqlNode.OrderByClause;
			if (this._orderByClause != null)
			{
				this._orderByClause.doParse(this, ESqlClause.orderby);
			}
			this._limitClause = tdeleteSqlNode.LimitClause;
			if (this._limitClause != null)
			{
				this._limitClause.doParse(this, ESqlClause.limit);
			}
			this._optionClause = tdeleteSqlNode.OptionClause;
			this._errorLoggingClause = tdeleteSqlNode.ErrorLoggingClause;
			int[] array = new int[this.tables.size()];
			for (int k = 0; k < this.tables.size(); k++)
			{
				TTable table = this.tables.getTable(k);
				if (table.AliasClause == null && table.BaseTable)
				{
					for (int l = 0; l < this.tables.size(); l++)
					{
						if (k != l)
						{
							TTable table2 = this.tables.getTable(l);
							if (table2.AliasClause != null && string.Compare(table2.AliasClause.ToString(), table.ToString(), StringComparison.CurrentCultureIgnoreCase) == 0)
							{
								array[k] = 1;
								for (int m = 0; m < table.ObjectNameReferences.size(); m++)
								{
									table2.ObjectNameReferences.addObjectName(table.ObjectNameReferences.getObjectName(m));
									table2.LinkedColumns.addObjectName(table.ObjectNameReferences.getObjectName(m));
									table.ObjectNameReferences.getObjectName(m).SourceTable = table2;
								}
							}
						}
					}
				}
			}
			for (int n = this.tables.size() - 1; n >= 0; n--)
			{
				if (array[n] == 1)
				{
					this.tables.removeTable(n);
				}
			}
			return 0;
		}

		// Token: 0x060004F5 RID: 1269 RVA: 0x002FC526 File Offset: 0x002FA726
		public override void accept(TParseTreeVisitor v)
		{
			v.preVisit(this);
			v.postVisit(this);
		}

		// Token: 0x060004F6 RID: 1270 RVA: 0x002FC538 File Offset: 0x002FA738
		public override void acceptChildren(TParseTreeVisitor v)
		{
			v.preVisit(this);
			if (this.CteList != null)
			{
				this.CteList.acceptChildren(v);
			}
			if (this.TopClause != null)
			{
				this.TopClause.acceptChildren(v);
			}
			this.TargetTable.acceptChildren(v);
			if (this.joins.size() > 0)
			{
				this.joins.acceptChildren(v);
			}
			if (this.OutputClause != null)
			{
				this.OutputClause.acceptChildren(v);
			}
			if (this.WhereClause != null)
			{
				this.WhereClause.acceptChildren(v);
			}
			if (this.ReturningClause != null)
			{
				this.ReturningClause.acceptChildren(v);
			}
			v.postVisit(this);
		}

		// Token: 0x04001124 RID: 4388
		private bool _fromKeyword;

		// Token: 0x04001125 RID: 4389
		private TErrorLoggingClause _errorLoggingClause;

		// Token: 0x04001126 RID: 4390
		private TOptionClause _optionClause;

		// Token: 0x04001127 RID: 4391
		private TSourceToken _deleteToken;

		// Token: 0x04001128 RID: 4392
		private TOrderBy _orderByClause;

		// Token: 0x04001129 RID: 4393
		private TLimitClause _limitClause;

		// Token: 0x0400112A RID: 4394
		private TJoinList _referenceJoins;
	}
}
